'use strict';

const BaseController = require('./base');

class Controller extends BaseController {
   constructor(...args){
     super(...args);
     this.model = 'role';//服务的名字
   }
   //返回所有的资源
   async getResources(){
    const { ctx } = this;
    let resources = await ctx.service[this.model].getResources();
    this.success(resources);
   }
   async setResources(){
    const { ctx } = this;
    let {roleId,resourceIds} = ctx.request.body;
    let affectedRows = await ctx.service[this.model].setResources(roleId,resourceIds);
    affectedRows>0?this.success('成功'):this.error('失败');
   }
   async getUsers(){
    const { ctx } = this;
    let users = await ctx.service[this.model].getUsers();
    this.success(users);
   }
   async setUsers(){
    const { ctx } = this;
    let {roleId,userIds} = ctx.request.body;
    let affectedRows = await ctx.service[this.model].setUsers(roleId,userIds);
    affectedRows>0?this.success('成功'):this.error('失败');
   }
}

module.exports = Controller;
